﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<html>
<head>
	<title></title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<script src="../../js/scripts/boot.js" type="text/javascript"></script>
	<script src="../../js/dktp.js" type="text/javascript"></script>
	<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
	
	<style type="text/css">
		html, body {
			margin: 0;
			padding: 0;
			border: 0;
			width: 100%;
			height: 100%;
			overflow: hidden;
		}
	</style>

</head>
<body>
	<div class="mini-panel" title="员工信息列表" style="width:100%;height:100%;"
		bodyStyle="padding: 0;">
	<div class="mini-toolbar" style="padding: 2px; border-bottom: 0;">
		<table style="width: 100%;">
			<tr>	
	            <td style="width:100%;">
                	<c:if test="${sessionScope.userType == 3}">
	                    <a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
	                    <a class="mini-button" iconCls="icon-remove" onclick="remove()">删除</a>       
                    </c:if>
	                <a class="mini-button" iconCls="icon-edit" onclick="edit()">修改</a>

                </td>
			</tr>
		</table>
	</div>
	<!--撑满页面-->
	<div class="mini-fit">

		<div id="datagrid1" class="mini-datagrid" showPager="false"   
			style="width: 100%; height: 100%;" idField="id" multiSelect="true"
		>
			<div property="columns">
				 <div type="checkcolumn" ></div>
				<div field="userNo" width="120" headerAlign="center" allowSort="true">员工编码</div>
				<div field="nickName" width="120" headerAlign="center" allowSort="true">员工名</div>
				<div field="name" width="100" headerAlign="center" allowSort="true">登录名</div>
				<div field="type" width="120" align="center" headerAlign="center"  renderer="onDocTypesRenderer" >用户类型</div>
				<div field="email" width="120" allowSort="true" >电子邮件</div>
				<div field="sex" width="60" align="center" headerAlign="center" renderer="onGenderRenderer">性别</div>
				<div field="birthday" width="100" align="center" headerAlign="center" dateFormat="yyyy-MM-dd">出生日期</div>
				<div field="telephone" width="100" align="center" headerAlign="center">手机号</div>
				<div field="address" width="120" align="center" headerAlign="center">家庭住址</div>
				<div field="qq" width="100" align="center" headerAlign="center">QQ</div>
				<div field="job" width="100" align="center" headerAlign="center" renderer="onDocTypesRenderer" >职务</div>
				<div field="dept" width="80" align="center" headerAlign="center" renderer="onDeptsRenderer" >所属部门</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	var userType = '<%= session.getAttribute("userType")%>';
	var userId = '<%= session.getAttribute("userId")%>';
	var user = {id:userId,type:userType};
	mini.parse();
	var grid = mini.get("datagrid1");
	grid.setUrl("/document/user/queryUserList.do");
	grid.load({id:userId,type:userType});
	//员工新增
     function add() {
         mini.open({
             targetWindow: window,
             url:"addUser.jsp",
             title: "员工添加", 
             width: 600, height: 500,
             onload: function () {
                 var iframe = this.getIFrameEl();
                 var data = { action: "new" };
                 iframe.contentWindow.SetData(data);
             },
             ondestroy: function (action) {
                 grid.reload();
                 if(action!="close"){
                 	dktp.showTips(action.success, action.message);
                 }
             }
         });
     }
	//编辑
    function edit() {
       var row = grid.getSelected();
       if (row) {
           mini.open({
        	   targetWindow: window,
               url:"addUser.jsp",
               title: "编辑员工", width: 600, height: 600,
               onload: function () {
                   var iframe = this.getIFrameEl();
                   var data = { action: "edit", id: row.id };
                   iframe.contentWindow.SetData(data);

               },
               ondestroy: function (action) {
                   //var iframe = this.getIFrameEl();

                   grid.reload();

               }
           });
           
       } else {
           alert("请选中一条记录");
       }
    }
	//删除用户信息
       function remove() {
           var rows = grid.getSelecteds();
           if (rows.length > 0) {
               if (confirm("确定删除选中记录？")) {
                   var ids = [];
                   for (var i = 0, l = rows.length; i < l; i++) {
                       var r = rows[i];
                       ids.push(r.id);
                   }
                   var id = ids.join(',');
                   grid.loading("操作中，请稍后......");
                   $.ajax({
                       url: "/document/user/deleteUser.do?ids=" +id,
                       success: function (text) {
                       	dktp.showTips(true,"删除成功！");
                           grid.reload();
                       },
                       error: function () {
                       }
                   });
               }
           } else {
               alert("请选中一条记录");
           }
       }
       ///////////////////////////////////////////////////////
       var docTypes = [ 
			{ "id": "1", "text": "工程师" },
			{ "id": "2", "text": "项目经理" } 
		];
       function onDocTypesRenderer(e) {
           for (var i = 0, l = docTypes.length; i < l; i++) {
               var g = docTypes[i];
               if (g.id == e.value) return g.text;
           }
           return "";
       }
       ///////////////////////////////////////////////////////
       var Genders = [{ id: 1, text: '男' }, { id: 2, text: '女'}];
       function onGenderRenderer(e) {
           for (var i = 0, l = Genders.length; i < l; i++) {
               var g = Genders[i];
               if (g.id == e.value) return g.text;
           }
           return "";
       }
       ///////////////////////////////////////////////////////
       var depts = [{ "id": "1", "text": "研发部" }, { "id": "2", "text": "测试部" },{"id": "3", "text": "企划部"},{"id": "4", "text": "市场营销部"}];
       function onDeptsRenderer(e) {
           for (var i = 0, l = depts.length; i < l; i++) {
               var g = depts[i];
               if (g.id == e.value) return g.text;
           }
           return "";
       }
</script>

</body>
</html>